package br.ufrj.ppgi.greco.controller;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.ufrj.ppgi.greco.model.dao.DAOWebHook;
import br.ufrj.ppgi.greco.model.entity.EntityWebHook;

@Resource
public class WebHookController
{
	private DAOWebHook dw;
	private Result result;
	
	public WebHookController(DAOWebHook dw, Result result)
	{
		this.dw = dw;
		this.result = result;
	}
	
	@Get
	@Path("/config/webHooks")
	public void listAllWebHooks()
	{
		this.result.include("webhooks",this.dw.getAll());
	}
	
	@Get
	@Path("/config/webHooks/new")
	public void newWebHook()
	{	
	}
	
	@Post
	@Path("/config/webHooks/create")
	public void createWebHook(EntityWebHook ew)
	{
		this.dw.insert(ew);
		this.result.redirectTo(WebHookController.class).listAllWebHooks();
	}
	
	@Get
	@Path("/config/webHooks/{id}")
	public void listWebHook(int id)
	{
		this.result.include("webhook",this.dw.getByID(id));
	}
	
	@Post
	@Path("/config/webHooks/update")
	public void updateWebHook(EntityWebHook ew)
	{
		this.dw.update(ew);
		this.result.redirectTo(WebHookController.class).listAllWebHooks();
	}
	
	@Get
	@Path("/config/webHooks/{id}/delete")
	public void deleteWebHook(int id)
	{
		this.dw.deleteByID(id);
		this.result.redirectTo(WebHookController.class).listAllWebHooks();
	}
	
}
